package com.approval.approvalapp.center.centerfragment;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.BjtjSjList;
import com.approval.approvalapp.center.adapter.BjtjSjAdapter;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseFragment;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


public class BjtjsjFragment extends BaseFragment {


    @Bind(R.id.rv)
    RecyclerView rv;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_bjtjsj;
    }

    @Override
    public void initView(View view) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("region_code" , SpUtil.getString(this.getActivity(),SpUtil.REGION_CODE,""));
        final ProgressDialog progressDialog = new ProgressDialog(this.getActivity());
        progressDialog.setMessage("正在请求数据");
        progressDialog.show();
        NetRequsetUtil.getInstance().netRequestPostJson("v1/user/queryDeptBJInfo", jsonObject.toString(),new NetDownResponse() {
            @Override
            public void success(String str) {
                List<BjtjSjList> bjtjSjLists = JSON.parseArray(str, BjtjSjList.class);
                rv.setLayoutManager(new LinearLayoutManager(BjtjsjFragment.this.getActivity()));
                BjtjSjAdapter bjtjSjAdapter = new BjtjSjAdapter();
                rv.setAdapter(bjtjSjAdapter);
                bjtjSjAdapter.setBjtjSjLists(bjtjSjLists);

            }

            @Override
            public void errowithresponse(String str) {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }
            }

            @Override
            public void erro() {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }
            }

            @Override
            public void finish() {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }

            }
        });

    }

    @Override
    public void initData() {

    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
